package cacheEntity

import (
	"time"
)

type Policy interface {
	Set(key string, val interface{})error
	SetHandle(h CacheEntity)
}

const CrossPolicyExpire = 10

type CrossPolicy struct {
	Expire time.Duration
	Cache  CacheEntity
}

func NewCrossPolicy() *CrossPolicy {
	return &CrossPolicy{Expire: time.Second * CrossPolicyExpire}
}

func (this *CrossPolicy)Set(key string, val interface{})error{
	expireOpt := func(c *Client) {
		c.Expire = this.Expire
	}
	return this.Cache.Set(key, val, expireOpt)
}

func (this *CrossPolicy)SetHandle(h CacheEntity){
	this.Cache = h
}
